package org.javaboy.ai.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import org.javaboy.ai.domain.Models;
import org.javaboy.ai.mapper.ModelsMapper;
import org.javaboy.ai.service.IModelsService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author javaboy
 * @since 2024-07-03
 */
@Service
public class ModelsServiceImpl extends ServiceImpl<ModelsMapper, Models> implements IModelsService {

    @Autowired
    ModelsMapper modelsMapper;

    @Override
    public List<Models> getAllModels() {
        LambdaQueryWrapper<Models> qw = new LambdaQueryWrapper<>();
        qw.eq(Models::getDelFlag, 1);
        qw.select(Models::getName, Models::getCharge, Models::getMultiple);
        qw.orderByAsc(Models::getOrderNum);
        return list(qw);
    }

    @Override
    public List<Models> selectModelsList(Models models) {
        return modelsMapper.selectModelsList(models);
    }

    @Override
    public boolean checkNameExists(Models models) {
        LambdaQueryWrapper<Models> qw = new LambdaQueryWrapper<>();
        qw.eq(Models::getDelFlag, 1);
        qw.eq(Models::getName, models.getName());
        if (models.getId() != null) {
            qw.ne(Models::getId, models.getId());
        }
        return exists(qw);
    }

    @Override
    public boolean deleteModels(Long[] modelsIds) {
        LambdaUpdateWrapper<Models> uw = new LambdaUpdateWrapper<>();
        uw.in(Models::getId, modelsIds);
        uw.set(Models::getDelFlag, 0);
        return update(uw);
    }
}
